import api from "../../http/apis/apis"
export default {
    namespaced: true,
    state: {
        LipeiData: {
            pageSize: 5,
            currentPage: 1,
            totalPages: 2,
            total: 0,
            data: [],
        },
    },
    mutations: {
        SetLipeiDate(state, newLipeiData) {
            state.LipeiData = newLipeiData;
        },

        //改变当前页
        setCurrent(state, newcurrent) {
            state.LipeiData.currentPage = newcurrent;
        },
        //每页显示数量
        setPageSize(state, newpagesize) {
            state.LipeiData.pageSize = newpagesize;
        },
    },
    actions: {
        //获取所有理赔信息
        async getLipeiAsync(context, value = '') {
            console.log('555', value);
            const { data } = await api.lipei.getAlllipei({
                value,
                pageSize: context.state.LipeiData.pageSize,
                currentPage: context.state.LipeiData.currentPage,
            });
            // console.log(data);
            if(data.status){
                context.commit('SetLipeiDate',data.data);
            }

        },
        //增加理赔信息
        async addLipeiAsync(context,lipei){
            const {data} = await api.lipei.addLipei(lipei);
            console.log(data);
            return data;
        },
        //获取销售的理赔信息
        async getSaleLipeiAsync(context,id){
            // console.log("哈啊哈"+id);
            const {data} = await api.lipei.getSaleLipei({
                pageSize: context.state.LipeiData.pageSize,
                currentPage: context.state.LipeiData.currentPage,
                id,
            });
            // console.log("销售员下",data);
            if(data.status){
                context.commit('SetLipeiDate',data.data);
            }
        },
        //同意理赔
        async agreeLipei(context, _id) {
            console.log("mode", _id);
            const { data } = await api.lipei.agreeLipei({ _id })
            if (data) {
                //刷新页面
                context.dispatch('getLipeiAsync')
            }
        },
        //撤回理赔
        async backLipeMsg(context, _id) {
            const { data } = await api.lipei.backLipei({ _id })
            if (data) {
                //刷新页面
                context.dispatch('getLipeiAsync')
            }
        },
        //删除理赔
        async deleteOneAsync(context, _id) {
            const { data } = await api.lipei.deleteOne(_id);
            console.log(data);
            if (data.status) {
                return data;
            } else {
                return data;
            }
        },
        //获取修改的理赔信息
        async getUpdataOneAsync(context,_id){
            // console.log("商店中",_id);
            const {data} = await api.lipei.getLipeiUpdataOne(_id);
            // console.log(data);
            if (data.status) {
                return data;
            } else {
                return data;
            }
        },
        //确认修改理赔
        async sureUpdataOneAsync(context,claim){
            console.log("商店中" ,claim);
            const {data} = await api.lipei.sureLipeiUpdataOne(claim);
            console.log(data);
            return data;
        }
    },
}

